﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using EmoneyWeiXinEntity;
using EmoneyWeiXinCommon;
namespace EmoneyWeiXinDAL
{
    public class TwoCodeTypeDal
    { 
        /// <summary>
        /// 查询二维码所有类别
        /// </summary>
        /// <returns></returns>
        public static List<TwoCode_TypeModel> getTwoCodeType(int weixinid, int pindex, int psize,out int total)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@weixinid", weixinid),
            new SqlParameter("@pindex", pindex),
            new SqlParameter("@psize", psize),
            new SqlParameter("@total", 0)
            };
            parameters[3].Direction = ParameterDirection.Output;
            List<TwoCode_TypeModel> result = SQLHelper.GetProcedureDataByColumnsLst<TwoCode_TypeModel>(Config.EmoneyWeiXin, "sp_twocode_type_Select_Page", parameters);
            total = Convert.ToInt32(parameters[3].Value);
            return result;
        }
        public static List<TwoCode_TypeModel> getTwoCodeType(int weixinid)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@weixinid", weixinid)
            };
            List<TwoCode_TypeModel> result = SQLHelper.GetProcedureDataByColumnsLst<TwoCode_TypeModel>(Config.EmoneyWeiXin, "sp_twocode_type_Select", parameters);
            return result;
        }
        /// <summary>
        /// 添加或者修改二维码所有类别
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int UpdateTwoCodeType(TwoCode_TypeModel obj)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@Sign", obj.Sign),
            new SqlParameter("@ID", obj.ID),
            new SqlParameter("@name", obj.name),
            new SqlParameter("@begin_val", obj.begin_val),
            new SqlParameter("@end_val", obj.end_val),
            new SqlParameter("@creator", obj.creator),
            new SqlParameter("@updatetime", obj.updatetime),
            new SqlParameter("@memo", obj.memo),
            new SqlParameter("@weixinid", obj.weixinid)
            };
            int result = SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_twocode_type_Update", parameters);
            return result;
        }
      
        /// <summary>
        /// 删除二维码所有类别
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static int deleteTwoCodeType(int ID,int weixinid)
        {
            SqlParameter[] parameters = new SqlParameter[] {  
            new SqlParameter("@ID", ID),
            new SqlParameter("@weixinid", weixinid)
            };
            int result = SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_twocode_type_Delete", parameters);
            return result;
        }
    }
}
